package demo.aqs;


import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author : feixiang.li
 * @since : 2025-09-16 09:49
 */
public class Main {
    public static void main(String[] args) throws Exception {
        int[] count = new int[1000];
//        MyLock lock = new MyLock();
        Lock lock = new ReentrantLock();
        List<Thread> threads = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            threads.add(new Thread(() -> {
                lock.lock();
                for (int j = 0; j < 1; j++) {
                    try {
                        Thread.sleep(2);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    count[0]--;
                }
                lock.unlock();
            }));
        }
        for (Thread thread : threads) {
            thread.start();
        }
        for (Thread thread : threads) {
            thread.join();
        }
        Thread.sleep(1000);
        System.out.println(count[0]);
    }
}
